﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pub;

namespace LZQXT.Test.Forms.PE
{
    public partial class FPESaveAS : Form
    {
        public CPE pe;

        public FPESaveAS()
        {
            InitializeComponent();
        }

        public void ShowDialog(CPE pe)
        {
            this.pe = pe;

            tboxEnd.Text = CPub.insertStrStepN(pe.FILE_LENGTH.ToString("X8"), 4, " ");

            ShowDialog();

        }

        private void FPESaveAS_Load(object sender, EventArgs e)
        {

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                Int32 i_begin = Convert.ToInt32(tboxBegin.Text.Replace(" ", ""), 16);
                Int32 i_end = Convert.ToInt32(tboxEnd.Text.Replace(" ", ""), 16);

                SaveFileDialog savedlg = new SaveFileDialog();
                if (savedlg.ShowDialog() == DialogResult.OK)
                {
                    FileStream fileStream = (FileStream)savedlg.OpenFile();
                    fileStream.Write(pe.FILE_ARRAY, i_begin, i_end - i_begin);
                    fileStream.Close();
                }

                this.Close();
            }
            catch (System.Exception ex)
            {
                CDebug.SendError(ex.ToString());
            }

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
